package com.jx.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.jx.dao.FindDidByDnameDao;
import com.jx.daoimpl.FindDidByDnameDaoimpl;
import com.jx.model.Admin;
import com.jx.service.AddAdminService;
import com.jx.servicrimpl.AddAdminServiceImpl;
/**
 * 增加管理员
 * @author zzzzzzz
 *
 */

public class AddAdminController extends HttpServlet{
	AddAdminService aas=new AddAdminServiceImpl();
	FindDidByDnameDao fddd=new FindDidByDnameDaoimpl();
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doPost(req, resp);
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		// TODO Auto-generated method stub
		req.setCharacterEncoding("utf8");
		//获取前台的数据
		String aname=req.getParameter("aname");
		int asex=Integer.parseInt(req.getParameter("asex"));
		int aage=Integer.parseInt(req.getParameter("aage"));
		String apsw=req.getParameter("apsw");
		String adep=req.getParameter("adep");
		int asalary=Integer.parseInt(req.getParameter("asalary"));
		//通过部门名字获取部门的Id
		int did=fddd.findDidByDname(adep);
		//创建admin对象
		Admin admin=new Admin(aname, apsw, did ,asex, aage, adep, asalary);
		//判断是否更新成功
		String data="0";
		if(aas.addAdminService(admin)){
			data="1";
		}else{
			data="0";
		}
		//传回数据
		PrintWriter pw=resp.getWriter();
		pw.write(data);
		
	}
}
